package com.lsy.weizhi2.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.TextView;

import com.lsy.weizhi2.R;
import com.zhy.autolayout.AutoLinearLayout;

/**
 * Created by 嗨哟 on 2017/4/7.
 */
public class AppraiseItem extends AutoLinearLayout {
    private Context context;
    private int image;
    private String name;
    private ImageView item_iv;
    private TextView item_tv;
    public AppraiseItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        LayoutInflater.from(context).inflate(R.layout.appraise_item,this,true);
        TypedArray typedArray=context.obtainStyledAttributes(attrs,R.styleable.MyCardBottom);
        image=typedArray.getResourceId(R.styleable.MyCardBottom_item_image,0);
        name=typedArray.getString(R.styleable.MyCardBottom_item_text);
        typedArray.recycle();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        item_iv= (ImageView) findViewById(R.id.item_iv);
        item_tv= (TextView) findViewById(R.id.item_tv);
        if(image!=0){
            item_iv.setImageResource(image);
        }
        if(!TextUtils.isEmpty(name)){
            item_tv.setText(name);
        }
    }

    public void setImage(int res){
        item_iv.setImageResource(res);
    }
}
